﻿<html>
	<head>
		<title>Termenyek listája</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="v-a.css" type="text/css">
	</head>
	<?php	
		session_start();
		require_once ('dbConnect.php');
		include ('functions.php');

		if(isset($_POST['Vissza'])) {
			$_SESSION['uzenet']="";
			header('Location: index.php');
			exit;
		}
		if(isset($_POST['Termenymodosit'])) {
			$_SESSION['uzenet']="";
			$_SESSION['editedtermeny']=$_POST['termenyID'][firstkey($_POST['Termenymodosit'])];
			$_SESSION['vissza']="termenylist.php";
			header('Location: termenyedit.php');
			exit;
		}
		if(isset($_POST['új'])) {
			$_SESSION['uzenet']="";
			$_SESSION['editedtermeny']="";
			$_SESSION['vissza']="termenylist.php";
			header('Location: termenyedit.php');
			exit;
		}
		
		if ((checkuser("admin")==0) and (checkuser("termelő")==0)){
			$_SESSION['uzenet']= "access denied";
		}
		
	?>
	
	<body>
		<table ><tr HEIGHT="10"><td WIDTH="80%">Termények listája</td><td WIDTH="20%"><?php include('kilepes.php');?></td></tr></table>
		<hr>
		<?php 
			printf($_SESSION['uzenet']);
		?>
		<hr>
		
		<form name='menu' method='post' action="termenylist.php">
		<table>
		<tr>
		<td>
			<input type='submit'  class='button' name='Vissza' value='<< vissza' />
		</td>
		<td>
			<input type='submit'  class='button' name='új' value='új' />
		</td>
		</tr>
		</table>
		
			<?php 
			
			if ((checkuser("admin")==1) or (checkuser("termelő")==1)){
				$query="CALL termenyek();";
				if (MyDatabase::getConnection()->multi_query($query)) {
						echo "<table id='one-column-emphasis'>";
						if ($result = MyDatabase::getConnection()->store_result()) {
							$j=0;
							while ($row = $result->fetch_row()) {
								echo "<tr>";
								echo "<input type=hidden name=termenyID[$j] value=$row[0]><td>$row[0]</td>";
								for ($i=1;$i<3;$i++){
									echo "<td>".$row[$i]."</td>";
								}
								echo '<td><img src="data:image/jpeg;base64,' . base64_encode( $row[3] ) . '" width="100" /></td>';
								echo "<td><input type='submit'  class='tablazatbutton' name='Termenymodosit[$j]' value='módosít' /></td>";
								$j++;
								echo "</tr>";
							}
							$result->free();
						}
						echo "</table>";
				}
				else{
					$_SESSION['uzenet']= MyDatabase::getConnection()->error;
					//printf(MyDatabase::getConnection()->error);
				}
			}
			?>
		</form>
	</body>
</html>

